package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Name;
import org.akomantoso.core.data.group.InlineElements;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * The element inline is a generic element for an inline. It can be placed
 * inside a block instead of any of the other inlines. The attribute name is
 * required and gives a name to the element.
 * 
 * <pre>
 * <xsd:element name="inline">
 * 		<xsd:complexType mixed="true">
 * 			<xsd:complexContent>
 * 				<xsd:extension base="inline">
 * 					<xsd:attributeGroup ref="name"/>
 * 				</xsd:extension>
 *  		</xsd:complexContent>
 * 		</xsd:complexType>
 * </xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 *  
 */
public final class Inline extends InlineType implements Name, InlineElements{

	public static final String ELEMENT = "inline";
	
	private String _name;
	
	/**
	 * @see org.akomantoso.core.data.attribute.Name#getName()
	 */
	public String getName() {
		return _name;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Name#setName(java.lang.String)
	 */
	public void setName(String name) {
		_name = name;
	}

	/**************************************************************************
	 * 							Externalisation
	 **************************************************************************/
	
	/**
	 * @see org.akomantoso.core.data.InlineType#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <E extends Output> void writeExternal(E out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeAttribute(out, Name.ATTRIBUTE, _name);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.InlineType#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <E extends Input> void readExternal(E in) throws IOException {
		_name = in.readAttribute(Name.ATTRIBUTE);
		super.readExternal(in);
	}
	
	/**************************************************************************
	 * 							Visitable
	 **************************************************************************/
	
	/**
	 * @see ec.ep.visitor.AKVisitable#accept(ec.ep.visitor.AKVisitor)
	 */
	public void accept(AKVisitor visitor) {
		internalAccept(visitor);
	}

}